angular.module('ionic-config', ['ionic'])

.config ($compileProvider) ->
    $compileProvider.imgSrcSanitizationWhitelist /^(https|http|file|blob|cdvfile):|data:image\//
.run ($ionicPlatform) ->
    $ionicPlatform.ready ->
        if window.cordova and window.cordova.plugins.Keyboard
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar true
        StatusBar.styleLightContent() if window.StatusBar

.config ($ionicConfigProvider, inWeixin) ->
    $ionicConfigProvider.platform.ios.tabs.style('standard')
    $ionicConfigProvider.platform.ios.tabs.position('bottom')
    $ionicConfigProvider.platform.android.tabs.style('standard')
    $ionicConfigProvider.platform.android.tabs.position('standard')
    $ionicConfigProvider.platform.ios.navBar.alignTitle('center')
    $ionicConfigProvider.platform.android.navBar.alignTitle('center')
    $ionicConfigProvider.platform.ios.backButton.previousTitleText('').icon('ion-ios-arrow-thin-left')
    $ionicConfigProvider.platform.android.backButton.previousTitleText('').icon('ion-android-arrow-back')
    $ionicConfigProvider.platform.ios.views.transition('ios')
    $ionicConfigProvider.platform.android.views.transition('android')
    if !inWeixin # 在Android的微信中不使用原生滚动
        $ionicConfigProvider.platform.android.scrolling.jsScrolling(false)

.run () ->
    document.addEventListener("deviceready", onDeviceReady, false)
    onDeviceReady = ->
        window.open = cordova.InAppBrowser.open

.run ($ionicPopup, $ionicLoading, $ionicPlatform, $state) ->
    $ionicPlatform.ready ->
        _.defer ->
            navigator.splashscreen?.hide()
